# coding: utf-8
from sqlalchemy import Column, DateTime, Float, ForeignKey, Integer, JSON, String
from sqlalchemy.orm import relationship
from sqlalchemy.dialects.mysql import TEXT
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
metadata = Base.metadata


class RestaurantInformation(Base):
    __tablename__ = 'restaurant_information'

    id = Column(Integer, primary_key=True)
    name = Column(String(255))
    address = Column(String(255))
    tel = Column(String(50))
    description = Column(TEXT)
    business_time = Column(String(255))
    other = Column(TEXT)


class MenuType(Base):
    __tablename__ = 'menu_type'

    id = Column(Integer, primary_key=True)
    position = Column(ForeignKey('restaurant_information.id', ondelete='CASCADE', onupdate='CASCADE'), index=True)
    name = Column(String(32))
    other = Column(TEXT)

    restaurant_information = relationship('RestaurantInformation')


class Goods(Base):
    __tablename__ = 'goods'

    id = Column(Integer, primary_key=True)
    name = Column(String(255))
    position = Column(ForeignKey('menu_type.id', ondelete='SET NULL', onupdate='CASCADE'), index=True)
    price = Column(Float(10))
    cushion = Column(Integer)
    offers = Column(String(255))
    parcel = Column(Float)
    description = Column(TEXT)
    sale_status = Column(Integer)
    picture = Column(TEXT)
    other = Column(TEXT)

    menu_type = relationship('MenuType')


class User(Base):
    __tablename__ = 'user'

    id = Column(Integer, primary_key=True)
    tel = Column(String(11))
    register_time = Column(DateTime)
    admin_status = Column(Integer)
    other = Column(TEXT)


class Order(Base):
    __tablename__ = 'order'

    id = Column(Integer, primary_key=True)
    user = Column(ForeignKey('user.id', ondelete='SET NULL', onupdate='CASCADE'))
    time = Column(DateTime)
    parcel = Column(Integer)
    goods = Column(JSON)
    position = Column(ForeignKey('restaurant_information.id', ondelete='CASCADE', onupdate='CASCADE'), index=True)
    offers = Column(Float)  # 折扣额
    note = Column(String(255))
    reserve_time = Column(DateTime)
    total = Column(Float)
    pay_status = Column(Integer)
    pick_code = Column(String(5))
    other = Column(TEXT)

    user_information = relationship('User')
    restaurant_information = relationship('RestaurantInformation')